﻿Public Class OdemePlaniRaporuIsveren2009 : Inherits OdemePlaniRaporuIsveren

	Sub New()
		MyBase.New()
		Yil = 2009
	End Sub

End Class

Public Class OdemePlaniRaporuIsveren
	Inherits ProcessReport

	Public Yil As Integer
	Dim Rsg, Rst As Recordset
	Dim Pesin As Boolean

	Public Overrides Sub GenericEvent(ByVal e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Start("Prim Borcu Ödeme Planı", "Kimlik bilgisini girin.")
				AddField("@Sigortali", "nl", "", "Sigortalı bilgisini girmelisiniz.")
			Case EventType.Shown
				If Not Arguments.ContainsKey("sno") Then Return
				Input("Sigortali") = Arguments("sno")
				Report.Focus()
			Case EventType.ValidateForm
				Rsg = Hukuk.Af.GenelIsverenOku(Local, Yil, Input("Sigortali"))
				If Rsg.EOF Then
					Warning("Bu işveren aftan yararlandırılmadı.")
					Focus("Sigortali")
					Exit Sub
				End If
				Rst = Hukuk.Af.TaksitIsverenOku(Local, Yil, Input("Sigortali"))
				Pesin = Rst.Select("tur='T'").EOF
				e.Result = True
			Case EventType.ReportHeader
				Dim Rs As Recordset = Sigortali.SnoAra(Local, Input("Sigortali"))
				Report.PrintHeader(Yil & " AFFI PRİM BORÇLARI ÖDEME PLANI")
				Report.SetColumns("Kimlik no.;Sigorta no.;Adı soyadı;Peşin öde.tar.", "1;1;3;1", "c;c;l;c", "-")
				Report.Print(Rs("kimlik"), Rs("sno"), RTrim(Rs("adi")) & " " & RTrim(Rs("soyadi")), Rsg("pesintar"))
				Report.SkipLine()
				Report.SetColumns("", "3;2;2;2;2;2;2;2;2;2", "c;m;m;m;m;m;m;m;m;m", "--")
				Report.Print("<rs=2><c><g=1>Dönem", "<cs=3><c><g=1>Toplam Borç", "<cs=3><c><g=1>Peşin Ödenecek", "<cs=3><c><g=1>Taksitlendirilecek")
				If Pesin Then
					Report.Print("<c><g=1>Anapara", "<c><g=1>Ceza", "<c><g=1>Toplam", "<c><g=1>Anapara", "<c><g=1>Ceza", "<c><g=1>Toplam", "<c><g=1>Anapara", "<c><g=1>Ceza", "<c><g=1>Toplam")
				Else
					Report.Print("<c><g=1>Anapara", "<c><g=1>Ceza (%30)", "<c><g=1>Toplam", "<c><g=1>Anapara", "<c><g=1>Ceza (%30)", "<c><g=1>Toplam", "<c><g=1>Anapara", "<c><g=1>Ceza (%30)", "<c><g=1>Toplam")
				End If
				Rst = Hukuk.Af.TaksitIsverenOku(Local, Yil, Input("Sigortali"))
				For j As Integer = 0 To 2
					Dim Donem As String = Choose(j + 1, "<g=1>2000 Öncesi", "<g=1>2000 Sonrası", "<g=1>Toplam")
					Dim f As String = Choose(j + 1, "donem < '2000'", "donem >= '2000'", "1 = 1")
					Report.Print(Donem,
					 Rst.Sum("anapara", f), Rst.Sum("ceza", f), Rst.Sum("toplam", f),
					 Rst.Sum("anapara", f & " and tur = 'P'"), Rst.Sum("ceza", f & " and tur = 'P'"), Rst.Sum("toplam", f & " and tur = 'P'"),
					 Rst.Sum("anapara", f & " and tur = 'T'"), Rst.Sum("ceza", f & " and tur = 'T'"), Rst.Sum("toplam", f & " and tur = 'T'"))
				Next
				Report.SkipLine()
			Case EventType.PageHeader
				Report.SetColumns("Dönem;Bordro;Anapara;Ceza;İnd.Ceza;Toplam;P/T;Öde.Tar.", "2;1;2;2;2;2;1;2", "c;c;m;m;m;m;c;d", "--")
			Case EventType.ReportDetail
				Rs = Rst.GroupBy("donem,bordro,tur,odetar,anapara=sum(anapara),ceza=sum(ceza)")
				If Pesin Then
					Dim ToplamCeza As Decimal = 0
					For Each Row In Rs
						Dim Ceza = Rs("ceza") / If(Rs("donem") > "2010", 0.1, 0.2)
						ToplamCeza += Ceza
						Report.Print(Rs("donem"), Rs("bordro"), Rs("anapara"), Ceza, Rs("ceza"), Rs("anapara") + Rs("ceza"), Rs("tur"), If(Rs("tur") = "P", DBNull.Value, Rs("odetar")))
					Next
					If Not Rs.Count = 0 Then Report.PrintTotal("", "", Rs.Sum("anapara"), ToplamCeza, Rs.Sum("ceza"), Rs.Sum("anapara") + Rs.Sum("ceza"), "", DBNull.Value)
				Else
					For Each Row In Rs
						Report.Print(Rs("donem"), Rs("bordro"), Rs("anapara"), Rs("ceza") / 0.3, Rs("ceza"), Rs("anapara") + Rs("ceza"), Rs("tur"), If(Rs("tur") = "P", DBNull.Value, Rs("odetar")))
					Next
					If Not Rs.Count = 0 Then Report.PrintTotal("", "", Rs.Sum("anapara"), Rs.Sum("ceza") / 0.3, Rs.Sum("ceza"), Rs.Sum("anapara") + Rs.Sum("ceza"), "", DBNull.Value)
				End If
		End Select
	End Sub

End Class
